package edu.avans.hartigehap.domain;

import java.util.Date;

import javax.persistence.*;

@Entity
public class DiscountPercentage extends Discount {
	private static final long serialVersionUID = 1L;
	
	/**
	 * A constructor for creating inactive discounts
	 * @param active
	 */
	public DiscountPercentage()
	{
		super();
	}
	
	/**
	 * A constructor for creating active discounts
	 * @param active
	 */
	public DiscountPercentage(Boolean active, Date date, double lValue){
		super(active, date, lValue);
	}

	@Override
	@Transient
	public double calculate(double price){
		//20 / 100 = 0.2
		double percentage = super.lValue / 100;
		//1 - 0.2 = 0.8
		double rest = 1 - percentage;
		//100 * 0.8 = 80
		double finalprice = price * rest;
		 return finalprice;
	 }
}

/*package edu.avans.hartigehap.domain;


import javax.persistence.*;
//fyi: l = local :)

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;

@Entity
@Table(name = "DISCOUNTable")
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class, property = "@id")
public class DiscountPercentage implements Discount {
	private static final long serialVersionUID = 1L;
	//an id for database use @ID
	int lId;
	//a name to get @NAME
	String lName;
	//a type to create a distinction between different discounts implementing discount @TYPE
	String lType;
	//the actual discount percentage @PERCENTAGE
	double lPercentage;
	
	public DiscountPercentage(String name, double percentage)
	{
		this.lName = name;
		this.lPercentage = percentage;
		setType();
	}
	
	//get and set the id for the database table DISCOUNT_ID
	@Id
	@GeneratedValue
	@Column(name = "DISCOUNT_ID")
	// optional
	public int getId() {
		return lId;
	}
	public void setId(int id) {
		this.lId = id;
	}
	
	@Column(name = "NAME")
	public String getName() {
		return lName;
	}
	public void setName(String name) {
		this.lName = name;
	}
	
	//get and sets the Type of dicount
	@Column(name = "TYPE")
	public String getType() {
		//possibly change to hardcoded
		return lType;
	}
	public void setType() {
		this.lType = "DiscountPercentage";
	}
	
	//gets and sets the percentage
	@Column(name = "VALUE")
	public double getDiscount(){
		return lPercentage;
	}
	public void setDiscount(double percentage)
	{
		this.lPercentage = percentage;
	}

}*/
